Why does adding a second attribute to a metaclass-property-closure mix change the first attribute?
By : Valerie Plate
Date : March 29 2020, 07:55 AM
|
How to add values to attribute added dynamically to property without attribute constructor(Reflection.Emit)
By : emcs thai
Date : March 29 2020, 07:55 AM
it should still fix some issue I was able to add Attribute and pass it values by constructor. But how to pass values when Attribute do not have constructor with appropriate parameters to pass. e.g. How to add this DisplayAttribute using Reflection.Emit? , You use CustomAttributeBuilder. For example: code :
var cab = new CustomAttributeBuilder(
ctor, ctorArgs,
props, propValues,
fields, fieldValues
);
prop.SetCustomAttribute(cab);
var attribType = typeof(DisplayAttribute);
var cab = new CustomAttributeBuilder(
attribType.GetConstructor(Type.EmptyTypes), // constructor selection
new object[0], // constructor arguments - none
new[] { // properties to assign to
attribType.GetProperty("Order"),
attribType.GetProperty("ResourceType"),
attribType.GetProperty("Name"),
},
new object[] { // values for property assignment
28,
typeof(CommonResources),
"DisplayComment"
});
prop.SetCustomAttribute(cab);
|
XSL: Search for an element having an attribute equals to one property of the current attribute
By : user3332224
Date : March 29 2020, 07:55 AM
wish of those help Perhaps it would be better to use a key for this, especially if there are many different RandomNode elements that you want to use for the lookup. Also, no need for named templates or parameters. XSLT Stylesheet code :
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="ref-id-to-id" match="RandomNode" use="@RefId"/>
<xsl:template match="Item">
<xsl:copy>
<xsl:attribute name="Value">
<xsl:value-of select="substring-after(@Value, ';')"/>
</xsl:attribute>
<xsl:attribute name="Provider-Id">
<xsl:value-of select="key('ref-id-to-id',substring-before(@Value,';'))/Id"/>
</xsl:attribute>
</xsl:copy>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<RootConfig>
<RandomNode RefId="519263a7-e01e-4cc8-911e-7660dca717bf">
<Id>101010101010</Id>
</RandomNode>
<Item Value="bf139890-2f7c-4784-8041-68aa5fe7beb1" Provider-Id="101010101010"/>
<Item Value="5fb8bea0-c79a-4a26-a532-4df59543bc5c" Provider-Id="101010101010"/>
<Item Value="4f01116a-06f8-4af3-9f4a-87c658eb8008" Provider-Id="101010101010"/>
</RootConfig>
|
if json attribute value is duplicate, compare its another number property and set attribute biggerDuplicate
By : KPavan Kumar
Date : March 29 2020, 07:55 AM
I hope this helps . I would do this by adding your number as part of the sort. I assume it is colorID Then create a temporary object that is a groupBy where name is used as keys and values are rrays of objects with that name. code :
let sorted = names.sort(function(a, b) {
// if names are same sort by colorId
return a.name.localeCompare(b.name) || a.colorId > b.colorId
});
let tmp = sorted.reduce(function(a, c) {
a[c.name] = a[c.name] || [];
a[c.name].push(c);
return a;
}, {});
Object.values(tmp).forEach(function(arr) {
let len = arr.length,
isDuplicate = len > 1;// if more than one in group they are all duplicates
arr.forEach(function(o, i) {
o.isDuplicate = isDuplicate;
if (isDuplicate) {
o.isBigger = i === len - 1;// already sorted by colorId so last one is biggest
}
});
});
console.log(sorted)
.as-console-wrapper {max-height: 100%!important;}
<script>
var names = [{
"order": 1,
"name": "a",
"shortName": "a",
"categoryId": 15070,
"colorId": 50
}, {
"order": 2,
"name": "s",
"shortName": "s",
"categoryId": 15071,
"colorId": 51
}, {
"order": 3,
"name": "h",
"shortName": "g",
"focused": 1513262627570,
"categoryId": 15074,
"colorId": 54
}, {
"order": 4,
"name": "h",
"shortName": "h",
"categoryId": 15075,
"colorId": 59
}];
</script>
|
python property referring to property/attribute of member attribute?
By : Balthazar
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I find the question a bit unclear, however I try to explain some context. code :
class A(object):
def __init__(self):
self.attribute = 1
self.member = 2
class B(object):
def __init__(self):
self.member = A()
B().member.member # returns 2
B().member.member = 10
b = B()
b.foo = 4 # define a new attribute on runtime
b.foo # returns 4
|